<?php
/**
 * Fonction d'appel du Web Service Sitra
 * 
 * @author Thomas Collet <tcollet@rhonetourisme.com>
 * @copyright Copyright (c) 2008, Thomas Collet
 * @link http://www.rhonetourisme.com/
 * @version v 0.1
 * @license http://creativecommons.org/licenses/by/3.0/
 * 
 * @param string $methode
 * @param array $params
 * @param array $options
 * @return array
 */

require_once('nusoap/0.7.3/nusoap.php');

class WebServiceSitraNuSOAP {
	
	var $config;

	function getIniFile($filepath) {
		$ini = parse_ini_file($filepath, TRUE);
		return $ini;
	}
		
	function search($methode, $searchparams, $options) {
		$config = WebServiceSitraNuSOAP::getIniFile('lib/ws_sitra_php4_client/settings/ws_sitra.ini.php');
		if(!$params[CodeLangue]){
			$codelangue = 'FR';
		}else{
			$codelangue = $params[CodeLangue];
		}
		$defaultparams = array(	'IdSiteWeb'=>$config[Main][IdSiteWeb],
								'CleWS'=>$config[Main][CleWS],
								'CodeLangue'=>$codelangue
								);
		if($options[DecodeUTF8]) {
		$decodeutf8 = true;
		unset($options[DecodeUTF8]);
		}
		else {
		$decodeutf8 = false;
		}
		if($methode=='RechercherTousTypesObts') {
			$defaultparams = array_merge($defaultparams, array('TypeSortie'=>'0', 'CodeRestitution'=>'0'));
		}
		// Adresse du WSDL du web service Sitra
		$mywsdl = $config[Main][WSDL];
		// Création de connexion au webservice 
		$client = new soapclient($mywsdl, $wsdl=true); 
		// On passe le paramètre d'encodage de caratères
		$client->decode_utf8 = $encoding;
		// On définit les paramètres, critères d'appel
		$params = array();
		$params['p_criteres'] = array_merge($defaultparams, $searchparams);
		// Gestion des erreurs
		$err = $client->getError(); 
		if ($err) 
		die('Constructor error: '.$err); 
		// Appel de la méthode
		$proxy = $client->getProxy(); 

		if($methode=='RechercherTousTypesObts') {
			$wsresult = $proxy->RechercherTousTypesObts($params, '');
	
		} else {
			$wsresult = $proxy->DetailObjet($params, '');
		}

		if ($options[ShowEnveloppe]) {
		// echo $proxy->request; // shows XML of SOAP request
		// echo $proxy->response; //shows XML of SOAP response
			global $SOAPenveloppe;
			if ($options[ShowEnveloppe]=='all') {
				$SOAPenveloppe=array('SOAPrequest'=>$proxy->request, 'SOAPresponse'=>$proxy->response);	
			}
			elseif ($options[ShowEnveloppe]=='SOAPresponse') {
				$SOAPenveloppe=array('SOAPresponse'=>$proxy->reponse);
			}
			elseif ($options[ShowEnveloppe]=='SOAPrequest') {
				$SOAPenveloppe=array('SOAPrequest'=>$proxy->request);
			}
		}
		
		return $wsresult;
	}
}
?>